package cn.appinfodb.controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import cn.appinfodb.pojo.DevUser;
import cn.appinfodb.service.DevUserService;
import cn.appinfodb.tools.Constants;

@Controller
@RequestMapping(value="/dev")
public class DevLoginController {
	private Logger logger = Logger.getLogger(DevLoginController.class);
	@Resource
	private DevUserService devUserService;
	
	@RequestMapping(value="/login")
	public String login(){
		logger.debug("LoginController welcome APPInfo==================");
		return "devlogin";
	}
	
	@RequestMapping(value="/dologin",method=RequestMethod.POST)
	public String doLogin(@RequestParam String devCode,@RequestParam String devPassword,HttpServletRequest request,HttpSession session) throws Exception{
		logger.debug("doLogin====================================");
		//����service�����������û�ƥ��
		DevUser devuser = devUserService.login(devCode, devPassword);
		if(null != devuser){//��¼�ɹ�
			//ҳ����ת��frame.jsp��
			session.setAttribute(Constants.DEV_USER_SESSION, devuser);
			return "redirect:/dev/flatform/main";
		}else{
			//ҳ����ת��login.jsp��������ʾ��Ϣ--ת��
			request.setAttribute("error", "�û��������벻��ȷ");
			return "login";
		}
	}
	@RequestMapping(value="/flatform/main")
	public String main(){
		return "developer/main";
	}

	
	@RequestMapping(value="/logout")
	public String logout(HttpSession session){
		//���session
		session.removeAttribute(Constants.DEV_USER_SESSION);
		return "devlogin";
	}
	
}
